this.BX=this.BX||{};(function(e,n,t,r,i){"use strict";var o="resolved";var a="pending";var s=BX.Landing.Utils,c=s.scrollTo,d=s.highlight;var u=function e(n){return BX.Landing.PageObject.getInstance().blocks().then((function(t){var r=t.get(n.block);if(!r){return Promise.reject()}r.forceInit();var i=r.nodes.getBySelector(n.selector);if(!i){return Promise.reject()}return c(i.node).then(d.bind(null,i.node,e.useRangeRect)).then((function(){return i.setValue(n.params.value,false,true)}))}))};u.useRangeRect=true;var l=u;var m=u;var g=u;var h=u;h.useRangeRect=false;var f=h;var v=u;v.useRangeRect=false;var p=BX.Landing.Utils,b=p.scrollTo,k=p.highlight;function y(e){return BX.Landing.PageObject.getInstance().blocks().then((function(n){var t=n.get(e.block);if(!t){return Promise.reject()}t.forceInit();var r=t.nodes.getBySelector(e.selector);if(!r){return Promise.reject()}return b(r.node).then((function(){return k(r.node)})).then((function(){if(r.onChangeTag){r.onChangeTag(e.params.value,true)}return true}))}))}var B=BX.Landing.Utils,P=B.scrollTo,L=B.highlight;function w(e){return BX.Landing.PageObject.getInstance().blocks().then((function(n){var t=n.get(e.block);t.forceInit();return P(t.node).then(L.bind(null,t.node)).then((function(){return t[e.params.direction](true)}))}))}var I=BX.Landing.Utils,C=I.scrollTo,X=I.highlight;function H(e){return t.PageObject.getInstance().blocks().then((function(n){var r=n.get(e.params.currentBlock);return new Promise((function(e){if(r){r.forceInit();return C(r.node).then(X.bind(null,r.node,false,true)).then(e)}e()})).then((function(){var n=BX.Landing.Main.getInstance();n.currentBlock=r;return t.PageObject.getInstance().view().then((function(t){n.currentArea=t.contentDocument.body.querySelector('[data-landing="'.concat(e.params.lid,'"]'));n.insertBefore=e.params.insertBefore;return n.onAddBlock(e.params.code,e.block,true)}))}))}))}var S=BX.Landing.Utils,j=S.scrollTo,E=S.highlight;function T(e){return BX.Landing.PageObject.getInstance().blocks().then((function(n){var t=n.get(e.block);t.forceInit();return j(t.node).then((function(){E(t.node);return t.deleteBlock(true)}))}))}var O=BX.Landing.Utils,R=O.scrollTo,N=O.highlight;function D(e){return BX.Landing.PageObject.getInstance().blocks().then((function(n){var t=n.get(e.block);if(t){t.forceInit()}if(!t){return Promise.reject()}return t})).then((function(n){return BX.Landing.PageObject.getInstance().view().then((function(t){var r=t.contentDocument.querySelector(e.params.selector).parentNode;return[n,r]}))})).then((function(e){return R(e[1]).then((function(){return e}))})).then((function(n){var t=n[0];return t.addCard({index:e.params.position,container:n[1],content:e.params.content,selector:e.params.selector},true).then((function(){var n=t.cards.getBySelector(e.params.selector);if(!n){return Promise.reject()}return N(n.node)}))}))["catch"]((function(){}))}var A=BX.Landing.Utils,U=A.scrollTo,_=A.highlight;function M(e){return BX.Landing.PageObject.getInstance().blocks().then((function(n){var t=n.get(e.block);t.forceInit();if(!t){return Promise.reject()}var r=e.params.selector+"@"+(e.params.position+1);var i=t.cards.getBySelector(r);if(!i){return Promise.reject()}return U(i.node).then(_.bind(null,i.node)).then((function(){return t.removeCard(r,true)}))}))}function x(e){var n=this;return new Promise((function(t,r){var i=e.params.tags||{};top.BX.onCustomEvent(n,"Landing:onHistoryAddNode",[i]);t()}))}function G(e){var n=this;return new Promise((function(t,r){var i=e.params.tags||{};top.BX.onCustomEvent(n,"Landing:onHistoryRemoveNode",[i]);t()}))}var W=BX.Landing.Utils,Y=W.scrollTo,F=W.slice;function K(e){return BX.Landing.PageObject.getInstance().blocks().then((function(n){var t=n.get(e.block);if(!t){return Promise.reject()}t.forceInit();t.initStyles();return t})).then((function(e){return Y(e.node).then((function(){return e}))})).then((function(n){var t=F(n.node.querySelectorAll(e.selector));if(n.selector===e.selector){t=[n.content]}t.forEach((function(n){n.className=e.params.value.className;if(e.params.value.style&&e.params.value.style!==""){n.style=e.params.value.style}else{n.removeAttribute("style")}}));return n})).then((function(n){var t=n.forms.find((function(n){return n.selector===e.selector||n.relativeSelector===e.selector}));if(t){t.fields.forEach((function(e){e.reset();e.onFrameLoad()}))}var r=n.styles.find((function(n){return n.selector===e.selector||n.relativeSelector===e.selector}));if(r){if(e.params.affect&&e.params.affect.length>0){r.setAffects(e.params.affect)}n.onStyleInputWithDebounce({node:r.node,data:r.getValue()},true)}}))}var q=BX.Landing.Utils,V=q.scrollTo,z=q.highlight;function J(e){return BX.Landing.PageObject.getInstance().blocks().then((function(n){var t=n.get(e.block);t.forceInit();return V(t.node).then((function(){void z(t.node);return t.updateContent(e.params.content,true)}))}))}var Q=BX.Landing.Utils,Z=Q.scrollTo,$=Q.highlight;function ee(e){var n=null;var t={};e.params.forEach((function(e){if(!n&&e.params.block){n=e.params.block}if(e.command==="editText"||e.command==="editImage"||e.command==="editEmbed"||e.command==="editMap"||e.command==="editIcon"||e.command==="editLink"){t[e.params.selector]=e.params.value}if(e.command==="updateDynamic"){t.dynamicParams=e.params.dynamicParams;t.dynamicState=e.params.dynamicState}if(e.command==="changeAnchor"){t.settings={id:e.params.value}}}));return BX.Landing.PageObject.getInstance().blocks().then((function(e){var r=e.get(n);if(r){r.forceInit();return Z(r.node).then((function(){void $(r.node);if(Object.keys(t).length>0){r.updateBlockState(t,true)}}))}}))}var ne=function e(t){babelHelpers.classCallCheck(this,e);this.id=n.Type.isStringFilled(t.id)?t.id:"#invalidCommand";this.command=n.Type.isFunction(t.command)?t.command:function(){}};function te(e){e.registerCommand(new ne({id:"editText",command:l}));e.registerCommand(new ne({id:"editImage",command:h}));e.registerCommand(new ne({id:"editEmbed",command:m}));e.registerCommand(new ne({id:"editMap",command:g}));e.registerCommand(new ne({id:"editIcon",command:f}));e.registerCommand(new ne({id:"editLink",command:v}));e.registerCommand(new ne({id:"cnangeNodeName",command:y}));e.registerCommand(new ne({id:"sortBlock",command:w}));e.registerCommand(new ne({id:"addBlock",command:H}));e.registerCommand(new ne({id:"removeBlock",command:T}));e.registerCommand(new ne({id:"updateStyle",command:K}));e.registerCommand(new ne({id:"addCard",command:D}));e.registerCommand(new ne({id:"removeCard",command:M}));e.registerCommand(new ne({id:"addNode",command:x}));e.registerCommand(new ne({id:"removeNode",command:G}));e.registerCommand(new ne({id:"updateContent",command:J}));e.registerCommand(new ne({id:"multiply",command:ee}));return Promise.resolve(e)}var re=new Worker("/bitrix/js/landing/history/src/worker/json-parse-worker.js");function ie(e){return new Promise((function(n){re.postMessage(e);re.addEventListener("message",(function(e){n(e.data)}))}))}var oe=new Worker("/bitrix/js/landing/history/src/worker/json-stringify-worker.js");function ae(e){return new Promise((function(n){oe.postMessage(e);oe.addEventListener("message",(function(e){n(e.data)}))}))}function se(e,t){return ie(window.localStorage.history).then((function(e){return n.Type.isPlainObject(e)?e:{}})).then((function(n){if(e in n){delete n[e]}return n})).then(ae).then((function(e){window.localStorage.history=e;return t}))}function ce(e){var t;try{t=i.Main.getInstance().id}catch(e){t=-1}return BX.Landing.Backend.getInstance().action("History::getForLanding",{lid:t}).then((function(t){e.stack=n.Text.toNumber(t.stackCount);e.step=Math.min(n.Text.toNumber(t.step),e.stack);return e}))["catch"]((function(n){return e}))}function de(e){var n={blocks:[],images:[]};e.forEach((function(e){if(e.command==="addBlock"){n.blocks.push(e.block)}if(e.command==="editImage"){n.images.push({block:e.block,id:e.redo.id})}}));return Promise.resolve(n)}function ue(e,n){return Promise.resolve(n)}function le(e){e.stack=[];e.step=-1;e.commandState=o;return Promise.resolve(e)}function me(e){var n=BX.Landing.PageObject.getRootWindow();BX.onCustomEvent(n.window,"BX.Landing.History:update",[e]);return Promise.resolve(e)}function ge(e){var n=BX.Landing.PageObject.getRootWindow();BX.onCustomEvent(n.window,"BX.Landing.History:init",[e]);return Promise.resolve(e)}var he=function e(t){babelHelpers.classCallCheck(this,e);this.block=t.block;this.selector=t.selector;this.command=n.Type.isStringFilled(t.command)?t.command:"#invalidCommand";this.params=t.params};var fe=function(e){babelHelpers.inherits(n,e);function n(){var e;babelHelpers.classCallCheck(this,n);e=babelHelpers.possibleConstructorReturn(this,babelHelpers.getPrototypeOf(n).call(this));e.layout.classList.add("landing-ui-highlight-animation");e.animationDuration=300;return e}babelHelpers.createClass(n,[{key:"show",value:function e(n,t){var r=this;BX.Landing.UI.Highlight.prototype.show.call(this,n,t);return new Promise((function(e){setTimeout(e,r.animationDuration);r.hide()}))}}],[{key:"getInstance",value:function e(){var r=t.PageObject.getRootWindow();if(!r.BX.Landing.History.Highlight.instance){r.BX.Landing.History.Highlight.instance=new n}return r.BX.Landing.History.Highlight.instance}}]);return n}(r.Highlight);var ve=function(){function e(){babelHelpers.classCallCheck(this,e);babelHelpers.defineProperty(this,"designerBlockId",null);this.type=e.TYPE_LANDING;this.stack=0;this.commands={};this.step=0;this.commandState=o;this.onStorage=this.onStorage.bind(this);try{this.landingId=i.Main.getInstance().id}catch(e){this.landingId=-1}n.Event.bind(window,"storage",this.onStorage);te(this).then(ce).then(ge)}babelHelpers.createClass(e,[{key:"setTypeDesignerBlock",value:function n(t){this.type=e.TYPE_DESIGNER_BLOCK;this.designerBlockId=t;return ce(this)}},{key:"getUndoAction",value:function n(){if(this.type===e.TYPE_DESIGNER_BLOCK){return"History::undoDesignerBlock"}return"History::undoLanding"}},{key:"getRedoAction",value:function n(){if(this.type===e.TYPE_DESIGNER_BLOCK){return"History::redoDesignerBlock"}return"History::redoLanding"}},{key:"getActionParams",value:function n(){if(this.type===e.TYPE_DESIGNER_BLOCK&&this.designerBlockId){return{blockId:this.designerBlockId}}return{lid:this.landingId}}},{key:"undo",value:function e(){var n=this;if(this.canUndo()){return BX.Landing.Backend.getInstance().action(this.getUndoAction(),this.getActionParams()).then((function(e){if(e){var t=e.params;var r=new he({block:t.block,selector:t.selector,command:e.command,params:t});return n.runCommand(r,-1)}return Promise.reject()})).then((function(e){return n.offset(-1).then(me)}))}return Promise.resolve(this)}},{key:"redo",value:function e(){var n=this;if(this.canRedo()){return BX.Landing.Backend.getInstance().action(this.getRedoAction(),this.getActionParams()).then((function(e){if(e){var t=e.params;var r=new he({block:t.block,selector:t.selector,command:e.command,params:t});return n.runCommand(r,1)}return Promise.reject()})).then((function(e){return n.offset(1).then(me)}))}return Promise.resolve(this)}},{key:"offset",value:function e(n){if(this.commandState===a){return Promise.resolve(this)}var t=this.step+n;if(t>=0&&t<=this.stack){this.step=t}return Promise.resolve(this)}},{key:"runCommand",value:function e(n,t){var r=this;if(n){var i=this.commands[n.command];if(i){this.commandState=a;return i.command(n).then((function(){r.commandState=o;return r}))["catch"]((function(){r.commandState=o;return r.offset(t)}))}}}},{key:"canUndo",value:function e(){return this.commandState!==a&&this.step>0&&this.stack>0&&this.step<=this.stack}},{key:"canRedo",value:function e(){return this.commandState!==a&&this.step<this.stack&&this.step>=0}},{key:"push",value:function e(n){if(this.step<this.stack){this.stack=this.step}this.step++;this.stack++;me(this)}},{key:"registerCommand",value:function e(n){if(n instanceof ne){this.commands[n.id]=n}}},{key:"removePageHistory",value:function e(n){return se(n,this).then((function(e){var t;try{t=BX.Landing.Main.getInstance().id}catch(e){t=-1}if(t===n){return le(e)}return Promise.reject()})).then(me)["catch"]((function(){}))}},{key:"onStorage",value:function e(n){if(n.key===null){if(!window.localStorage.history){le(this).then(me)}}}},{key:"onNewBranch",value:function e(n){var t=this;return de(n,this).then((function(e){return ue(e,t)}))}}],[{key:"getInstance",value:function e(){var n=t.PageObject.getRootWindow();if(!n.BX.Landing.History.instance){n.BX.Landing.History.instance=new BX.Landing.History}return n.BX.Landing.History.instance}}]);return e}();babelHelpers.defineProperty(ve,"TYPE_LANDING","L");babelHelpers.defineProperty(ve,"TYPE_DESIGNER_BLOCK","D");babelHelpers.defineProperty(ve,"Command",ne);babelHelpers.defineProperty(ve,"Entry",he);babelHelpers.defineProperty(ve,"Highlight",fe);e.History=ve})(this.BX.Landing=this.BX.Landing||{},BX,BX.Landing,BX.Landing.UI,BX.Landing);
//# sourceMappingURL=history.bundle.map.js